package com.yy.controller;

import com.yy.pojo.User;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@RestController
public class RequestController {

    private final AopAutoConfiguration aopAutoConfiguration;

    public RequestController(AopAutoConfiguration aopAutoConfiguration) {
        this.aopAutoConfiguration = aopAutoConfiguration;
    }

    //    @RequestMapping("/simpleParam")
//    public String simpleParam(HttpServletRequest request){
//
//        String name = request.getParameter("name");
//        String ageStr = request.getParameter("age");
//
//        Integer age = Integer.parseInt(ageStr);
//
//        System.out.println(name + " " + age);
//        return "OK";
//    }
//    @RequestMapping("/simpleParam")
//    public String simpleParam(String name,Integer age){
//        System.out.println(name + " " + age);
//        return "OK";
//    }
    @RequestMapping("/simpleParam")
    public String simpleParam(@RequestParam(name = "name") String username, Integer age){
        System.out.println(username + " " + age);
        return "OK";
    }

    //2.实体参数
    @RequestMapping("/simplePojo")
    public String simplePojo(User user){
        System.out.println(user);
        return "OK";
    }

    @RequestMapping("/complexPojo")
    public String complexPojo(User user){
        System.out.println(user);
        return "OK";
    }

    @RequestMapping("/arrayParam")
    public String arrayParam(String[] hobby){
        System.out.println(Arrays.toString(hobby));
        return "OK";
    }

    @RequestMapping("/listParam")
    public String listParam(@RequestParam List<String> hobby){
        System.out.println(hobby);
        return "OK";
    }

    @RequestMapping("/dateParam")
    public String dateParam(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime updateTime){
        System.out.println(updateTime);
        return "OK";
    }

    @RequestMapping("/jsonParam")
    public String jsonParam(@RequestBody User user){
        System.out.println(user);
        return "OK";
    }
}
